home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™ 1987-1994
/
MacHack™ '87
/
DA's
/
DlgSans ƒ
/
myDlgSansRscr.LSP
next >
Wrap
Text File
|
1987-04-18
|
12KB
|
364 lines
{ ; Title: myDialogSansRscr™ }
{ ; Author : Paul Nevai }
{ ; Version: 1.0 }
{ ; April 16, 1987 }
{ ; This is a Use&EnjoyNetWare product: If you like it you must drop me a Thank Paul note. }
{ ; Have Orthogonal Polynomials }
{ ; Will Travel }
{ ; Paul Nevai pgn@osupyr.uucp ( PREFERRED ) }
{ ; Department of Mathematics nevai-p@osu-eddie.uucp }
{ ; The Ohio State University ...!ihnp4!cbatt!osupyr!pgn }
{ ; 231 West Eighteenth Avenue TS1171@OHSTVMA.bitnet }
{ ; Columbus, OH 43210, U. S. A. 1-614-292-5688 }
{ ; To build an FKEY Code Resource: }
{ ; (1) Remove the file "RemoveMe" and the Library "MacPasLib" from this project, }
{ ; (2) Add the Library "DA PasLib", }
{ ; (3) and then Build and Save As a CODE Resource with the Code Resource TYPE equal to }
{ ; "FKEY", ID equal to "0" (Zero) which is the Key that the FKEY is installed on. }
{ ; The NAME should be zFKey. }
{ ; (4) If you want FKEY function from a MasterFKey then use ResEdit or equivalent }
{ ; to set TYPE = FKEY and CREATOR = Paul }
{ ; }
{ ; Thanks to: Lofty Becker, Steve Brecher, Carlos Weber, Joel West, the guys on the Net, }
{ ; How to Write Macintosh Software, Inside Macintosh, Lightspeed Pascal, }
{ ; Macintosh Revealed }
{ ; }
{ ; This material is based upon work supported by the National Science Foundation under }
{ ; Grant No. DMS 84-19525. }
UNIT zFKEY;
INTERFACE
{ A code resource must have no global variables. All shared variables are }
{ local procedure MAIN, and shared among its sub procedures }
PROCEDURE main; { a code resource must have a procedure called MAIN }
IMPLEMENTATION
FUNCTION PaulFilter (theDialog : DialogPtr; {based on How to Write Macintosh Software, p. 312}
VAR theEvent : EventRecord; {has some extras not fully used by this program}
VAR itemNumber : integer) : Boolean;
CONST
returnCode = $24; {KeyCode}
enterCode = $34; {KeyCode}
cancelCode = $32; {KeyCode}
ETX = $03; {EnterKey, charCode}
BS = $08; {BackSpaceKey, charCode}
CR = $0D; {ReturnKey, charCode}
ESC = $1B; {Clear on KeyPad, charCode}
FS = $1C; {LeftArrow}
GS = $1D; {RighttArrow}
RS = $1E; {UpArrow}
US = $1F; {DownArrow}
CancelKey = $60; {charCode}
Finder = 3;
reallyCancel = 12;
VAR
keyCode : integer;
chCode : integer;
ch : Char;
cmdDown : Boolean;
theDialogPeek : DialogPeek;
theType : integer;
theItem : Handle;
theBox : Rect;
finalTicks : longint;
BEGIN {PaulFilter}
theDialogPeek := DialogPeek(theDialog);
WITH theEvent DO
IF what <> keyDown THEN
PaulFilter := FALSE
ELSE
BEGIN
PaulFilter := TRUE;
keyCode := BitAnd(message, KeyCodeMask);
keyCode := BitShift(keyCode, -8);
chCode := BitAnd(message, CharCodeMask);
ch := CHR(chCode);
cmdDown := (BitAnd(modifiers, CmdKey) = CmdKey);
IF (chCode IN [ETX, CR]) OR (ch IN ['d', 'D', 's', 'S']) THEN
BEGIN
GetDItem(theDialog, OK, theType, theItem, theBox);
HiliteControl(ControlHandle(theItem), OK);
Delay(8, finalTicks);
HiliteControl(ControlHandle(theItem), 0);
itemNumber := OK;
END
ELSE IF (chCode IN [ESC]) OR (ch IN ['`', 'c', 'C']) THEN
BEGIN
GetDItem(theDialog, Cancel, theType, theItem, theBox);
HiliteControl(ControlHandle(theItem), Cancel);
Delay(8, finalTicks);
HiliteControl(ControlHandle(theItem), 0);
itemNumber := Cancel;
END
ELSE IF (ch IN ['x', 'X']) THEN
BEGIN
GetDItem(theDialog, Cancel, theType, theItem, theBox);
HiliteControl(ControlHandle(theItem), Cancel);
Delay(20, finalTicks);
HiliteControl(ControlHandle(theItem), 0);
itemNumber := reallyCancel;
END
ELSE IF (ch IN ['f', 'F']) THEN
BEGIN
GetDItem(theDialog, Finder, theType, theItem, theBox);
HiliteControl(ControlHandle(theItem), Cancel);
Delay(8, finalTicks);
HiliteControl(ControlHandle(theItem), 0);
itemNumber := Finder;
END;
END;
END; {PaulFilter}
PROCEDURE DrawUserItem (theDialog : DialogPtr; {DrawUserItem in Dialog}
itemNumber : integer);
VAR
itemType : integer;
itemHandle : Handle;
dispRect : Rect;
BEGIN
SetPort(theDialog);
PenSize(3, 3);
GetDItem(theDialog, OK, itemType, itemHandle, dispRect);
InsetRect(dispRect, -4, -4);
FrameRoundRect(dispRect, 16, 16);
PenNormal;
END; {DrawUserItem}
PROCEDURE main;
CONST
ShutDown = 1;
Finder = 3;
reallyCancel = 12;
TYPE
FreudTuran = (Freud, Turan);
VAR
myDialog : DialogPtr;
myDialogPeek : DialogPeek;
dStorage : DialogRecord;
itemNumber, howManyTimes : integer;
itemType : integer;
itemHandle : Handle;
dispRect : Rect;
HMT, zMessage : str255;
justAFlag : FreudTuran;
PROCEDURE DialogSansResources (VAR myDialog : DialogPtr; {create Dialog in memory}
VAR dStorage : DialogRecord);
CONST
CR = $0D;
p0 = 'Please click appropriate button!'; {static text}
line1 = 'Paul Nevai'; {static text}
line2 = 'pgn@osupyr.uucp'; {static text}
line3 = '73057,172.CompuServe'; {static text}
line4 = 'TS1171@OHSTVMA.bitnet'; {static text}
buttonTitleLength = 8;
statTextLength = 2;
buttonNu = 3;
statTextNu = 2;
userNu = 1;
TYPE {these are for creating the Dialog Template in memory}
TitleT = PACKED ARRAY[1..buttonTitleLength] OF char;
TextT = PACKED ARRAY[1..statTextLength] OF char;
ButtonTitleT = ARRAY[1..buttonNu] OF STRING[buttonTitleLength];
StatTextTitleT = ARRAY[1..statTextNu] OF STRING[statTextLength];
StatTextRectT = ARRAY[1..statTextNu] OF Rect;
ButtonsType = ARRAY[1..buttonNu] OF RECORD
CtlHndl : Handle;
Itemrect : Rect;
ItemType, ItemLen : SignedByte;
zTitle : TitleT;
END;
StatTextsType = ARRAY[1..statTextNu] OF RECORD
statTextHndl : Handle;
Itemrect : Rect;
ItemType, ItemLen : SignedByte;
zText : TextT;
END;
UserType = ARRAY[1..userNu] OF RECORD
userItemPtr : ProcPtr;
Itemrect : Rect;
ItemType, ItemLen : SignedByte;
END;
ItemListT = RECORD
ItemCountM1 : integer;
myButtons : ButtonsType;
myStatTexts : StatTextsType;
frame : UserType;
END;
ItemListTPtr = ^ItemListT;
ItemListTHdl = ^ItemListTPtr;
VAR
DITLHdl : ItemListTHdl;
frameRect, dRect : Rect;
itemList : Handle;
itemNumber : integer;
zBTitle : ButtonTitleT;
zSTTitle : StatTextTitleT;
zSTRect : StatTextRectT;
zAddress, theString : str255;
i, j : integer;
itemType : integer;
itemHandle : Handle;
dispRect : Rect;
BEGIN {DialogSansResources}
BEGIN {titles}
zBTitle[1] := 'ShutDown';
zBTitle[2] := ' Cancel ';
zBTitle[3] := ' Finder ';
zAddress := concat(line1, CHR(CR), line2, CHR(CR), line3, CHR(CR), line4);
SetRect(zSTRect[1], 8, 10, 302, 39);
SetRect(zSTRect[2], 140, 45, 300, 110);
END;
DITLHdl := ItemListTHdl(NewHandle(SizeOf(ItemListT))); {create the DialogTemplate}
HLock(handle(DITLHdl));
WITH DITLHdl^^ DO
BEGIN
ItemCountM1 := buttonNu + statTextNu + userNu - 1;
FOR j := 1 TO buttonNu DO
WITH myButtons[j] DO
BEGIN
CtlHndl := NIL;
BEGIN {this little juggling places buttons in the right order on the screen}
IF j = 1 THEN
i := 2
ELSE IF j = 2 THEN
i := 3
ELSE IF j = 3 THEN
i := 1
ELSE
i := j;
END; {juggling}
SetRect(Itemrect, 10 + (i - 1) * 100, 120, 100 + (i - 1) * 100, 138);
IF j = 1 THEN
frameRect := Itemrect;
ItemType := CtrlItem + BtnCtrl;
ItemLen := buttonTitleLength;
zTitle := zBTitle[j];
END;
FOR j := 1 TO statTextNu DO
WITH myStatTexts[j] DO
BEGIN
statTextHndl := NIL;
Itemrect := zSTRect[j];
ItemType := statText;
ItemLen := statTextLength;
NumToString(j - 1, theString);
zText[1] := '^';
zText[2] := theString[1];
END;
WITH frame[1] DO
BEGIN
userItemPtr := @DrawUserItem;
Itemrect := frameRect;
ItemType := UserItem;
ItemLen := 0;
END;
END;
HUnLock(handle(DITLHdl));
SetRect(dRect, 100, 100, 410, 250);
itemList := Handle(DITLHdl);
ParamText(p0, zAddress, '', '');
myDialog := NewDialog(@dStorage, dRect, '', TRUE, DBoxProc, WindowPtr(-1), FALSE, 0, itemList);
END; {DialogSansResources}
PROCEDURE ExitFromTheShell (ShutItDownToo : Boolean); {based on Joel West's NetWare}
TYPE
VCBPtr = ^VCB;
VAR
vcbp : VCBPtr;
refnumStartUp, refnum, dmyerr : INTEGER;
kjuHeaderPtr : QHdrPtr;
BEGIN
kjuHeaderPtr := GetVCBQHdr;
vcbp := VCBPtr(kjuHeaderPtr^.QHead);
refnumStartUp := vcbp^.vcbVRefNum;
WHILE vcbp <> NIL DO
BEGIN
refnum := vcbp^.vcbVRefNum;
vcbp := VCBPtr(vcbp^.qLink);
dmyerr := FlushVol(NIL, refnum);
IF ShutItDownToo THEN
IF refnumStartUp <> refnum THEN
BEGIN
dmyerr := Eject(NIL, refnum);
dmyerr := UnmountVol(NIL, refnum);
END;
END;
IF ShutItDownToo THEN
BEGIN
dmyerr := Eject(NIL, refnumStartUp);
dmyerr := UnmountVol(NIL, refnumStartUp);
ReStart
END
ELSE
ExitToShell;
END; {ExitFromTheShell (ShutItDownToo : Boolean)}
BEGIN {main}
howManyTimes := 0;
justAFlag := Freud; {kludge,kludge}
DialogSansResources(myDialog, dStorage);
FlushEvents(everyEvent, 0);
InitCursor;
REPEAT
ModalDialog(@PaulFilter, itemNumber);
IF itemNumber = Cancel THEN
BEGIN
GetDItem(myDialog, 4, itemType, itemHandle, dispRect);
CASE howManyTimes OF
0 :
BEGIN
zMessage := 'Good Job! Alas, there is no way to cancel it.';
howManyTimes := 1;
END;
1 :
BEGIN
zMessage := 'Sorry, but I told you already that you can''t cancel it.';
howManyTimes := howManyTimes + 1;
END;
OTHERWISE
IF (justAFlag = Freud) AND (howManyTimes = 5 * trunc(howManyTimes / 5)) THEN
BEGIN
zMessage := 'OK, you can cancel it by typing ''x'' or ''X''.';
justAFlag := Turan; {kludge,kludge}
END
ELSE
BEGIN
NumToString(howManyTimes, HMT);
zMessage := concat('Didn''t I tell you ', HMT, ' times already that you can''t cancel it?');
SetIText(itemHandle, zMessage);
howManyTimes := howManyTimes + 1;
justAFlag := Freud; {kludge,kludge}
END;
END; {case howManyTimes of}
SetIText(itemHandle, zMessage);
END; {itemNumber = zCancel}
UNTIL itemNumber IN [ShutDown, Finder, reallyCancel];
myDialogPeek := DialogPeek(myDialog);
CloseDialog(myDialog);
DisposHandle(myDialogPeek^.items);
CASE itemNumber OF
ShutDown :
ExitFromTheShell(TRUE);
Finder :
ExitFromTheShell(FALSE);
reallyCancel :
; {typing either 'x' or'X' lets one really cancel the Dialog}
OTHERWISE
ExitFromTheShell(FALSE);
END;
END; { main }
END. { unit }